package pe.edu.upc.dsd.whereeat.base.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import pe.edu.upc.dsd.whereeat.base.dao.BaseDAO;
import pe.edu.upc.dsd.whereeat.base.domain.BaseEntity;
import pe.edu.upc.dsd.whereeat.base.service.BaseService;


@Service
public abstract class BaseServiceImpl<T extends BaseEntity, ID extends Serializable> implements
		BaseService<T, ID> {

	protected abstract BaseDAO<T, ID> getBaseDAO();

	@Transactional
	public void save(T entity) throws Exception {
		// TODO Auto-generated method stub
		getBaseDAO().save(entity);
	}

	@Transactional
	public void update(T entity) throws Exception {
		// TODO Auto-generated method stub
		getBaseDAO().update(entity);
	}

	@Transactional
	public void delete(T entity) throws Exception {
		// TODO Auto-generated method stub
		getBaseDAO().delete(entity);
	}

	public T findById(ID id) throws Exception {
		// TODO Auto-generated method stub
		return getBaseDAO().findById(id);
	}

	public List<T> findAll() throws Exception {
		// TODO Auto-generated method stub
		return getBaseDAO().findAll();
	}

	public T findSingleObject(String queryString, Object... params)
			throws Exception {
		// TODO Auto-generated method stub
		return getBaseDAO().findSingleObject(queryString, params);
	}

	public List<T> executeQuery(String queryString, Integer startPosition,
			Integer maxResult, Object... params) throws Exception {
		// TODO Auto-generated method stub
		return getBaseDAO().executeQuery(queryString, startPosition, maxResult,
				params);
	}

}
